{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  Read Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train (87020, 26)\n",
      "test (37717, 24)\n"
     ]
    }
   ],
   "source": [
    "train = pd.read_csv('1Train.csv')\n",
    "test = pd.read_csv('1Test.csv')\n",
    "print(\"train\",train.shape)\n",
    "print(\"test\",test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>City</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>DOB</th>\n",
       "      <th>Lead_Creation_Date</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>...</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>Female</td>\n",
       "      <td>Delhi</td>\n",
       "      <td>20000</td>\n",
       "      <td>23-May-78</td>\n",
       "      <td>15-May-15</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>CYBOSOL</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>G</td>\n",
       "      <td>S122</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Mumbai</td>\n",
       "      <td>35000</td>\n",
       "      <td>07-Oct-85</td>\n",
       "      <td>04-May-15</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>TATA CONSULTANCY SERVICES LTD (TCS)</td>\n",
       "      <td>...</td>\n",
       "      <td>13.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>G</td>\n",
       "      <td>S122</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>Male</td>\n",
       "      <td>Panchkula</td>\n",
       "      <td>22500</td>\n",
       "      <td>10-Oct-81</td>\n",
       "      <td>19-May-15</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ALCHEMIST HOSPITALS LTD</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S143</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>Male</td>\n",
       "      <td>Saharsa</td>\n",
       "      <td>35000</td>\n",
       "      <td>30-Nov-87</td>\n",
       "      <td>09-May-15</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>BIHAR GOVERNMENT</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S143</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>Male</td>\n",
       "      <td>Bengaluru</td>\n",
       "      <td>100000</td>\n",
       "      <td>17-Feb-84</td>\n",
       "      <td>20-May-15</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>GLOBAL EDGE SOFTWARE</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>N</td>\n",
       "      <td>Web-browser</td>\n",
       "      <td>B</td>\n",
       "      <td>S134</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID  Gender       City  Monthly_Income        DOB  \\\n",
       "0  ID000002C20  Female      Delhi           20000  23-May-78   \n",
       "1  ID000004E40    Male     Mumbai           35000  07-Oct-85   \n",
       "2  ID000007H20    Male  Panchkula           22500  10-Oct-81   \n",
       "3  ID000008I30    Male    Saharsa           35000  30-Nov-87   \n",
       "4  ID000009J40    Male  Bengaluru          100000  17-Feb-84   \n",
       "\n",
       "  Lead_Creation_Date  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "0          15-May-15             300000.0                  5.0           0.0   \n",
       "1          04-May-15             200000.0                  2.0           0.0   \n",
       "2          19-May-15             600000.0                  4.0           0.0   \n",
       "3          09-May-15            1000000.0                  5.0           0.0   \n",
       "4          20-May-15             500000.0                  2.0       25000.0   \n",
       "\n",
       "                         Employer_Name    ...    Interest_Rate Processing_Fee  \\\n",
       "0                              CYBOSOL    ...              NaN            NaN   \n",
       "1  TATA CONSULTANCY SERVICES LTD (TCS)    ...            13.25            NaN   \n",
       "2              ALCHEMIST HOSPITALS LTD    ...              NaN            NaN   \n",
       "3                     BIHAR GOVERNMENT    ...              NaN            NaN   \n",
       "4                 GLOBAL EDGE SOFTWARE    ...              NaN            NaN   \n",
       "\n",
       "   EMI_Loan_Submitted Filled_Form  Device_Type  Var2  Source  Var4  LoggedIn  \\\n",
       "0                 NaN           N  Web-browser     G    S122     1         0   \n",
       "1              6762.9           N  Web-browser     G    S122     3         0   \n",
       "2                 NaN           N  Web-browser     B    S143     1         0   \n",
       "3                 NaN           N  Web-browser     B    S143     3         0   \n",
       "4                 NaN           N  Web-browser     B    S134     3         1   \n",
       "\n",
       "  Disbursed  \n",
       "0         0  \n",
       "1         0  \n",
       "2         0  \n",
       "3         0  \n",
       "4         0  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method DataFrame.info of                 ID  Gender          City  Monthly_Income        DOB  \\\n",
       "0      ID000002C20  Female         Delhi           20000  23-May-78   \n",
       "1      ID000004E40    Male        Mumbai           35000  07-Oct-85   \n",
       "2      ID000007H20    Male     Panchkula           22500  10-Oct-81   \n",
       "3      ID000008I30    Male       Saharsa           35000  30-Nov-87   \n",
       "4      ID000009J40    Male     Bengaluru          100000  17-Feb-84   \n",
       "5      ID000010K00    Male     Bengaluru           45000  21-Apr-82   \n",
       "6      ID000011L10  Female    Sindhudurg           70000  23-Oct-87   \n",
       "7      ID000012M20    Male     Bengaluru           20000  25-Jul-75   \n",
       "8      ID000013N30    Male         Kochi           75000  26-Jan-72   \n",
       "9      ID000014O40  Female        Mumbai           30000  12-Sep-89   \n",
       "10     ID000016Q10    Male        Mumbai           25000  01-Jan-76   \n",
       "11     ID000018S30  Female         Surat           25000  13-Oct-89   \n",
       "12     ID000019T40  Female          Pune           24000  22-May-90   \n",
       "13     ID000021V10    Male   Bhubaneswar           27000  24-Jun-82   \n",
       "14     ID000022W20  Female        Howrah           28000  09-Feb-89   \n",
       "15     ID000023X30    Male       Chennai           42000  08-May-82   \n",
       "16     ID000024Y40    Male      Ludhiana           28994  11-Oct-85   \n",
       "17     ID000025Z00  Female         Delhi           20000  06-Jan-90   \n",
       "18     ID000027B20  Female     Bengaluru           33000  14-Jul-76   \n",
       "19     ID000028C30    Male     Panchkula           31500  29-Aug-82   \n",
       "20     ID000029D40    Male       Lucknow           60000  14-Jul-85   \n",
       "21     ID000031F10  Female     Bengaluru           16000  01-Feb-83   \n",
       "22     ID000032G20  Female          Pune           12000  25-Jan-87   \n",
       "23     ID000033H30    Male     Bardhaman           30000  10-Feb-73   \n",
       "24     ID000034I40    Male        Indore           45000  12-Dec-75   \n",
       "25     ID000035J00  Female     Hyderabad           45000  11-Jan-81   \n",
       "26     ID000037L20    Male     Bengaluru           22843  08-Jun-91   \n",
       "27     ID000040O00  Female         Delhi            2900  22-Jul-82   \n",
       "28     ID000041P10  Female       Udaipur            8500  20-May-94   \n",
       "29     ID000043R30    Male        Mumbai          200000  05-Feb-85   \n",
       "...            ...     ...           ...             ...        ...   \n",
       "86990  ID124780G00    Male         Kochi           80000  16-May-73   \n",
       "86991  ID124782I20    Male         Kochi           80000  16-May-73   \n",
       "86992  ID124783J30  Female         Delhi           25000  19-Jul-92   \n",
       "86993  ID124785L00  Female        Mumbai           35000  01-Dec-81   \n",
       "86994  ID124786M10    Male    Jamshedpur           15000  12-Sep-84   \n",
       "86995  ID124787N20    Male      Firozpur           30000  27-Jul-78   \n",
       "86996  ID124788O30    Male          Pune           50000  30-May-86   \n",
       "86997  ID124789P40    Male         Delhi           32000  21-Oct-86   \n",
       "86998  ID124790Q00    Male     Ahmedabad           45000  31-Aug-56   \n",
       "86999  ID124791R10  Female         Baddi           13000  05-Jun-90   \n",
       "87000  ID124792S20  Female        Palwal           51524  01-Nov-62   \n",
       "87001  ID124793T30    Male    Coimbatore           53000  29-Jun-87   \n",
       "87002  ID124794U40  Female         Baddi           13000  05-Jun-90   \n",
       "87003  ID124795V00    Male        Rajkot           40000  01-Jan-60   \n",
       "87004  ID124796W10    Male    Aurangabad           32000  22-May-78   \n",
       "87005  ID124798Y30    Male       Nellore          116000  21-Feb-69   \n",
       "87006  ID124799Z40  Female     Bengaluru           10000  01-May-89   \n",
       "87007  ID124802C20    Male     Hyderabad           15000  02-May-88   \n",
       "87008  ID124803D30  Female          Pune           35000  31-Mar-81   \n",
       "87009  ID124804E40    Male         Delhi          133000  14-Aug-85   \n",
       "87010  ID124806G10    Male        Nagpur           28000  10-Jun-73   \n",
       "87011  ID124808I30    Male     Bengaluru           15000  01-Jun-90   \n",
       "87012  ID124810K00    Male     Bengaluru           46000  02-Jan-85   \n",
       "87013  ID124811L10    Male  Secunderabad           24000  01-Jan-90   \n",
       "87014  ID124812M20  Female          Pune           49000  31-May-82   \n",
       "87015  ID124813N30  Female         Ajmer           71901  27-Nov-69   \n",
       "87016  ID124814O40  Female         Kochi           16000  01-Dec-90   \n",
       "87017  ID124816Q10    Male     Bengaluru          118000  28-Jan-72   \n",
       "87018  ID124818S30    Male     Bengaluru           98930  27-Apr-77   \n",
       "87019  ID124821V10    Male        Mumbai           42300  31-Oct-88   \n",
       "\n",
       "      Lead_Creation_Date  Loan_Amount_Applied  Loan_Tenure_Applied  \\\n",
       "0              15-May-15             300000.0                  5.0   \n",
       "1              04-May-15             200000.0                  2.0   \n",
       "2              19-May-15             600000.0                  4.0   \n",
       "3              09-May-15            1000000.0                  5.0   \n",
       "4              20-May-15             500000.0                  2.0   \n",
       "5              20-May-15             300000.0                  5.0   \n",
       "6              01-May-15                  6.0                  5.0   \n",
       "7              20-May-15             200000.0                  5.0   \n",
       "8              02-May-15                  0.0                  0.0   \n",
       "9              03-May-15             300000.0                  3.0   \n",
       "10             02-May-15            1000000.0                  5.0   \n",
       "11             02-May-15             140000.0                  4.0   \n",
       "12             02-May-15             500000.0                  4.0   \n",
       "13             09-May-15             200000.0                  5.0   \n",
       "14             13-May-15             100000.0                  1.0   \n",
       "15             05-May-15             500000.0                  3.0   \n",
       "16             08-May-15             300000.0                  5.0   \n",
       "17             01-May-15             100000.0                  5.0   \n",
       "18             24-May-15             500000.0                  5.0   \n",
       "19             01-May-15             500000.0                  5.0   \n",
       "20             01-May-15                  0.0                  0.0   \n",
       "21             01-May-15                  0.0                  0.0   \n",
       "22             01-May-15                  0.0                  0.0   \n",
       "23             01-May-15            1000000.0                  5.0   \n",
       "24             01-May-15                  0.0                  0.0   \n",
       "25             01-May-15             300000.0                  1.0   \n",
       "26             01-May-15             300000.0                  2.0   \n",
       "27             01-May-15                  0.0                  0.0   \n",
       "28             01-May-15             100000.0                  2.0   \n",
       "29             01-May-15            1000000.0                  0.0   \n",
       "...                  ...                  ...                  ...   \n",
       "86990          31-Jul-15                  0.0                  0.0   \n",
       "86991          31-Jul-15                  0.0                  0.0   \n",
       "86992          31-Jul-15              80000.0                  1.0   \n",
       "86993          31-Jul-15                  0.0                  0.0   \n",
       "86994          31-Jul-15             200000.0                  3.0   \n",
       "86995          31-Jul-15                  0.0                  0.0   \n",
       "86996          31-Jul-15             500000.0                  2.0   \n",
       "86997          31-Jul-15                  NaN                  NaN   \n",
       "86998          31-Jul-15                  0.0                  0.0   \n",
       "86999          31-Jul-15             200000.0                  2.0   \n",
       "87000          31-Jul-15             300000.0                  5.0   \n",
       "87001          31-Jul-15                  0.0                  0.0   \n",
       "87002          31-Jul-15             100000.0                  2.0   \n",
       "87003          31-Jul-15             700000.0                  0.0   \n",
       "87004          31-Jul-15            1000000.0                  5.0   \n",
       "87005          31-Jul-15            1000000.0                  5.0   \n",
       "87006          31-Jul-15             100000.0                  2.0   \n",
       "87007          31-Jul-15             200000.0                  3.0   \n",
       "87008          31-Jul-15            1000000.0                  5.0   \n",
       "87009          31-Jul-15             200000.0                  0.0   \n",
       "87010          31-Jul-15                  0.0                  0.0   \n",
       "87011          31-Jul-15                  0.0                  0.0   \n",
       "87012          31-Jul-15             300000.0                  3.0   \n",
       "87013          31-Jul-15             300000.0                  3.0   \n",
       "87014          31-Jul-15             400000.0                  5.0   \n",
       "87015          31-Jul-15            1000000.0                  5.0   \n",
       "87016          31-Jul-15                  0.0                  0.0   \n",
       "87017          31-Jul-15                  0.0                  0.0   \n",
       "87018          31-Jul-15             800000.0                  5.0   \n",
       "87019          31-Jul-15                  0.0                  0.0   \n",
       "\n",
       "       Existing_EMI                                      Employer_Name  \\\n",
       "0               0.0                                            CYBOSOL   \n",
       "1               0.0                TATA CONSULTANCY SERVICES LTD (TCS)   \n",
       "2               0.0                            ALCHEMIST HOSPITALS LTD   \n",
       "3               0.0                                   BIHAR GOVERNMENT   \n",
       "4           25000.0                               GLOBAL EDGE SOFTWARE   \n",
       "5           15000.0       COGNIZANT TECHNOLOGY SOLUTIONS INDIA PVT LTD   \n",
       "6               0.0                               CARNIVAL CRUISE LINE   \n",
       "7            2597.0                    GOLDEN TULIP FLORITECH PVT. LTD   \n",
       "8               0.0                                       SIIS PVT LTD   \n",
       "9               0.0                                     SOUNDCLOUD.COM   \n",
       "10              0.0                                      KRISHNA KUMAR   \n",
       "11              0.0                             S D JAIN MODERN SCHOOL   \n",
       "12              0.0              K.E.M. HOSPITAL RESEARCH CENTRE, PUNE   \n",
       "13           4600.0                       GI STAFFING SERVICES PVT LTD   \n",
       "14           1200.0                             MCX STOCK EXCHANGE LTD   \n",
       "15              0.0                                 SMEC INDIA PVT LTD   \n",
       "16           2550.0                                 UNIPARTS INDIA LTD   \n",
       "17              0.0                                  INTEC CAPITAL LTD   \n",
       "18           7000.0                                        N RAVIKUMAR   \n",
       "19          10000.0                    S P SINGLA CONSTRUCTION PVT LTD   \n",
       "20              0.0                         TCS AND ASSOCIATES PVT LTD   \n",
       "21              0.0                            RELIANCE RETAIL LIMITED   \n",
       "22              0.0                          TERNT HYPERMARKET LIMITED   \n",
       "23           5000.0                                      MD.IDRIS KHAN   \n",
       "24              0.0                                      DILIP SOLANKI   \n",
       "25              0.0                  CIGNITI SOFTWARE SERVICES PVT LTD   \n",
       "26              0.0                 SYNERGY BUSINESS SOLUTIONS PVT LTD   \n",
       "27              0.0       INVENTIV INTERNATIONAL PHARMA SERVICES P LTD   \n",
       "28              0.0                                           ARC GATE   \n",
       "29              0.0                          APT BUSINESS SERVICES LLP   \n",
       "...             ...                                                ...   \n",
       "86990           0.0                                          CA CAMPUS   \n",
       "86991           0.0                                          CA CAMPUS   \n",
       "86992           0.0                                    IBM CORPORATION   \n",
       "86993           0.0                    PUNJAB AND SIND BANK (P AND SB)   \n",
       "86994           0.0                                LIVELY HOOD SYSTEMS   \n",
       "86995       10000.0             CIGNA TTK HEALTH INSURANCE COMPANY LTD   \n",
       "86996           0.0                               XYZ MULTNATIONAL LTD   \n",
       "86997           NaN                                                NaN   \n",
       "86998           0.0                    BHARAT SANCHAR NIGAM LTD (BSNL)   \n",
       "86999        5000.0                            JOHNSON AND JOHNSON LTD   \n",
       "87000       23648.0                                              DHBVN   \n",
       "87001           0.0  RENAULT NISSAN TECHNOLOGY AND BUSINESS CENTRE ...   \n",
       "87002        5000.0                            JOHNSON AND JOHNSON LTD   \n",
       "87003        8450.0                                                KJO   \n",
       "87004           0.0                                                  0   \n",
       "87005           0.0                                          APTRANSCO   \n",
       "87006        3500.0                                       FAROOQ AHMED   \n",
       "87007         500.0                       FIRSTOBJECT TECHNOLOGIES LTD   \n",
       "87008           0.0                  INNOBELLA MKTG AND ENTMT SOLN P L   \n",
       "87009       34000.0  OPERA SOLUTIONS MANAGEMENT CONSULTING SERVICES...   \n",
       "87010           0.0                       UTTAM VALUE STEEL LTD,WARDHA   \n",
       "87011           0.0                                             AIRTEL   \n",
       "87012           0.0       COGNIZANT TECHNOLOGY SOLUTIONS INDIA PVT LTD   \n",
       "87013           0.0                                   INDIAN AIR FORCE   \n",
       "87014           0.0                               INFOSYS TECHNOLOGIES   \n",
       "87015       14500.0                                       MAYO COLLEGE   \n",
       "87016           0.0                     KERALA COMMUNICATORS CABLE LTD   \n",
       "87017           0.0                  BANGALORE INSTITUTE OF TECHNOLOGY   \n",
       "87018       13660.0                           FIRSTSOURCE SOLUTION LTD   \n",
       "87019           0.0                                GOVERNMENT OF INDIA   \n",
       "\n",
       "         ...    Interest_Rate Processing_Fee  EMI_Loan_Submitted Filled_Form  \\\n",
       "0        ...              NaN            NaN                 NaN           N   \n",
       "1        ...            13.25            NaN             6762.90           N   \n",
       "2        ...              NaN            NaN                 NaN           N   \n",
       "3        ...              NaN            NaN                 NaN           N   \n",
       "4        ...              NaN            NaN                 NaN           N   \n",
       "5        ...            13.99         1500.0             6978.92           N   \n",
       "6        ...              NaN            NaN                 NaN           N   \n",
       "7        ...              NaN            NaN                 NaN           N   \n",
       "8        ...            14.85        26000.0            30824.65           Y   \n",
       "9        ...            18.25         1500.0            10883.38           N   \n",
       "10       ...            20.00         6600.0            17485.96           N   \n",
       "11       ...              NaN            NaN                 NaN           N   \n",
       "12       ...              NaN            NaN                 NaN           N   \n",
       "13       ...            18.00         4500.0             5078.69           N   \n",
       "14       ...              NaN            NaN                 NaN           N   \n",
       "15       ...              NaN            NaN                 NaN           N   \n",
       "16       ...            15.50         6000.0             7215.96           N   \n",
       "17       ...              NaN            NaN                 NaN           N   \n",
       "18       ...              NaN            NaN                 NaN           N   \n",
       "19       ...              NaN            NaN                 NaN           N   \n",
       "20       ...              NaN            NaN                 NaN           N   \n",
       "21       ...              NaN            NaN                 NaN           N   \n",
       "22       ...              NaN            NaN                 NaN           N   \n",
       "23       ...              NaN            NaN                 NaN           N   \n",
       "24       ...              NaN            NaN                 NaN           N   \n",
       "25       ...              NaN            NaN                 NaN           N   \n",
       "26       ...            20.00         2600.0            13232.91           N   \n",
       "27       ...              NaN            NaN                 NaN           N   \n",
       "28       ...              NaN            NaN                 NaN           N   \n",
       "29       ...              NaN            NaN                 NaN           N   \n",
       "...      ...              ...            ...                 ...         ...   \n",
       "86990    ...            15.25        28800.0            40259.00           Y   \n",
       "86991    ...            23.00        28800.0            46154.12           Y   \n",
       "86992    ...              NaN            NaN                 NaN           N   \n",
       "86993    ...              NaN            NaN                 NaN           N   \n",
       "86994    ...            37.00         3800.0             8811.27           N   \n",
       "86995    ...              NaN            NaN                 NaN           N   \n",
       "86996    ...              NaN            NaN                 NaN           N   \n",
       "86997    ...              NaN            NaN                 NaN           N   \n",
       "86998    ...            14.85        16200.0            22481.36           Y   \n",
       "86999    ...              NaN            NaN                 NaN           N   \n",
       "87000    ...              NaN            NaN                 NaN           N   \n",
       "87001    ...              NaN            NaN                 NaN           N   \n",
       "87002    ...              NaN            NaN                 NaN           N   \n",
       "87003    ...              NaN            NaN                 NaN           N   \n",
       "87004    ...              NaN            NaN                 NaN           N   \n",
       "87005    ...            15.75        15000.0            36278.14           N   \n",
       "87006    ...              NaN            NaN                 NaN           N   \n",
       "87007    ...            31.50         3800.0             8222.69           Y   \n",
       "87008    ...            15.25        17400.0            20811.58           Y   \n",
       "87009    ...            13.99         1000.0             5464.29           N   \n",
       "87010    ...            14.85        10000.0            13877.39           Y   \n",
       "87011    ...              NaN            NaN                 NaN           N   \n",
       "87012    ...            13.00         2400.0            10108.19           N   \n",
       "87013    ...              NaN            NaN                 NaN           N   \n",
       "87014    ...              NaN            NaN                 NaN           N   \n",
       "87015    ...              NaN            NaN                 NaN           N   \n",
       "87016    ...            35.50         4800.0             9425.76           Y   \n",
       "87017    ...              NaN            NaN                 NaN           N   \n",
       "87018    ...              NaN            NaN                 NaN           N   \n",
       "87019    ...            13.99         3450.0            18851.81           N   \n",
       "\n",
       "       Device_Type  Var2  Source  Var4  LoggedIn Disbursed  \n",
       "0      Web-browser     G    S122     1         0         0  \n",
       "1      Web-browser     G    S122     3         0         0  \n",
       "2      Web-browser     B    S143     1         0         0  \n",
       "3      Web-browser     B    S143     3         0         0  \n",
       "4      Web-browser     B    S134     3         1         0  \n",
       "5      Web-browser     B    S143     3         1         0  \n",
       "6      Web-browser     B    S133     1         0         0  \n",
       "7      Web-browser     B    S159     3         0         0  \n",
       "8           Mobile     C    S122     5         0         0  \n",
       "9      Web-browser     B    S133     1         0         0  \n",
       "10     Web-browser     B    S133     4         0         0  \n",
       "11     Web-browser     B    S122     1         0         0  \n",
       "12     Web-browser     B    S133     1         0         0  \n",
       "13     Web-browser     B    S133     4         0         0  \n",
       "14     Web-browser     B    S151     1         0         0  \n",
       "15     Web-browser     B    S159     3         0         0  \n",
       "16     Web-browser     E    S122     1         1         0  \n",
       "17     Web-browser     B    S122     1         0         0  \n",
       "18     Web-browser     E    S133     1         0         0  \n",
       "19     Web-browser     E    S133     3         0         0  \n",
       "20          Mobile     F    S133     2         0         0  \n",
       "21          Mobile     C    S133     1         0         0  \n",
       "22          Mobile     C    S133     1         0         0  \n",
       "23     Web-browser     E    S133     3         0         0  \n",
       "24     Web-browser     E    S133     3         0         0  \n",
       "25     Web-browser     B    S133     3         0         0  \n",
       "26     Web-browser     E    S133     4         0         0  \n",
       "27          Mobile     C    S133     1         0         0  \n",
       "28     Web-browser     B    S133     1         0         0  \n",
       "29     Web-browser     B    S159     2         0         0  \n",
       "...            ...   ...     ...   ...       ...       ...  \n",
       "86990       Mobile     G    S122     5         0         0  \n",
       "86991       Mobile     G    S122     5         0         0  \n",
       "86992  Web-browser     G    S122     7         0         0  \n",
       "86993       Mobile     G    S122     3         0         0  \n",
       "86994  Web-browser     G    S122     4         0         0  \n",
       "86995  Web-browser     G    S122     3         0         0  \n",
       "86996  Web-browser     G    S122     3         0         0  \n",
       "86997  Web-browser     G    S122     1         0         0  \n",
       "86998       Mobile     G    S122     5         0         0  \n",
       "86999  Web-browser     G    S122     1         0         0  \n",
       "87000  Web-browser     G    S122     1         0         0  \n",
       "87001       Mobile     G    S122     3         0         0  \n",
       "87002  Web-browser     G    S122     1         0         0  \n",
       "87003  Web-browser     G    S122     3         0         0  \n",
       "87004  Web-browser     G    S122     7         0         0  \n",
       "87005  Web-browser     G    S122     3         0         0  \n",
       "87006  Web-browser     G    S122     1         0         0  \n",
       "87007  Web-browser     G    S122     5         0         0  \n",
       "87008  Web-browser     G    S122     5         0         0  \n",
       "87009  Web-browser     G    S122     4         0         0  \n",
       "87010       Mobile     G    S122     5         0         0  \n",
       "87011       Mobile     G    S122     3         0         0  \n",
       "87012  Web-browser     G    S122     4         0         0  \n",
       "87013  Web-browser     G    S122     3         0         0  \n",
       "87014  Web-browser     G    S122     3         0         0  \n",
       "87015  Web-browser     G    S122     3         0         0  \n",
       "87016       Mobile     G    S122     5         0         0  \n",
       "87017       Mobile     G    S122     3         0         0  \n",
       "87018  Web-browser     G    S122     3         0         0  \n",
       "87019  Web-browser     G    S122     4         0         0  \n",
       "\n",
       "[87020 rows x 26 columns]>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.info\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png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JEndGCrSXkhSST46NP+HSd7XaduXJXljj21J+4qhIu2dh4E3JDly0o0Ma2+SlvY5Q0XaO9sY/Gzte3ZcsOORRpLvt+9XJflKklVJ/iPJB5K8Ocn1SW5J8pyhzbwmyb+0ca9r689K8uEk65LcnORtQ9u9NslfA7eMc6elXZnxv1Ev7QcuBG5O8qHHsc6LgRcweEX7JuDiqlqc5F3AmcC727j5wCuB5wDXJnkucBrwYFX9apInAP+W5J/a+MXAMVV1197ulDQdhoq0l6rqe0lWAu8E/nfE1dZV1X0ASf4T2B4KtwC/MTRuVVU9CtyZZBPwfOAE4EVDR0FPBRYAjwDXGyiaJENF6uNjwI3ApUO1bbRTzEkCHDK07OGh6UeH5h/lp/+73PE9SsXgpwfOrKq1wwuSvAr4wfTal/rwmorUQVVtBVYBwy8v/CZwbJteChw8jU2fkuSgdp3l2cAdDF7k+fYkBwMk+eUkT5lu71JPhorUz0eB4bvA/gp4ZZLrgZcxvaOIO4CvAF8Efr+qfgRcDGwAbkxyK/CXeNZB+wnfUixJ6sYjFUlSN4aKJKkbQ0WS1I2hIknqxlCRJHVjqEiSujFUJEndGCqSpG7+HwspRKyxXbXnAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.countplot(train['Disbursed']);\n",
    "plt.xlabel(\"Disbursed\");\n",
    "plt.xlabel(\"Number\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>8.702000e+04</td>\n",
       "      <td>8.694900e+04</td>\n",
       "      <td>86949.000000</td>\n",
       "      <td>8.694900e+04</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>5.240700e+04</td>\n",
       "      <td>52407.000000</td>\n",
       "      <td>27726.000000</td>\n",
       "      <td>27420.000000</td>\n",
       "      <td>27726.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>5.884997e+04</td>\n",
       "      <td>2.302507e+05</td>\n",
       "      <td>2.131399</td>\n",
       "      <td>3.696228e+03</td>\n",
       "      <td>4.961503</td>\n",
       "      <td>3.950106e+05</td>\n",
       "      <td>3.891369</td>\n",
       "      <td>19.197474</td>\n",
       "      <td>5131.150839</td>\n",
       "      <td>10999.528377</td>\n",
       "      <td>2.949805</td>\n",
       "      <td>0.029350</td>\n",
       "      <td>0.014629</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2.177511e+06</td>\n",
       "      <td>3.542068e+05</td>\n",
       "      <td>2.014193</td>\n",
       "      <td>3.981021e+04</td>\n",
       "      <td>5.670385</td>\n",
       "      <td>3.082481e+05</td>\n",
       "      <td>1.165359</td>\n",
       "      <td>5.834213</td>\n",
       "      <td>4725.837644</td>\n",
       "      <td>7512.323050</td>\n",
       "      <td>1.697720</td>\n",
       "      <td>0.168785</td>\n",
       "      <td>0.120062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000e+04</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>11.990000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>1176.410000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.650000e+04</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000e+05</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>15.250000</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>6491.600000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.500000e+04</td>\n",
       "      <td>1.000000e+05</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>4000.000000</td>\n",
       "      <td>9392.970000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.000000e+04</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>3.500000e+03</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>5.000000e+05</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>6250.000000</td>\n",
       "      <td>12919.040000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>4.445544e+08</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>3.000000e+06</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>37.000000</td>\n",
       "      <td>50000.000000</td>\n",
       "      <td>144748.280000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "count    8.702000e+04         8.694900e+04         86949.000000  8.694900e+04   \n",
       "mean     5.884997e+04         2.302507e+05             2.131399  3.696228e+03   \n",
       "std      2.177511e+06         3.542068e+05             2.014193  3.981021e+04   \n",
       "min      0.000000e+00         0.000000e+00             0.000000  0.000000e+00   \n",
       "25%      1.650000e+04         0.000000e+00             0.000000  0.000000e+00   \n",
       "50%      2.500000e+04         1.000000e+05             2.000000  0.000000e+00   \n",
       "75%      4.000000e+04         3.000000e+05             4.000000  3.500000e+03   \n",
       "max      4.445544e+08         1.000000e+07            10.000000  1.000000e+07   \n",
       "\n",
       "               Var5  Loan_Amount_Submitted  Loan_Tenure_Submitted  \\\n",
       "count  87020.000000           5.240700e+04           52407.000000   \n",
       "mean       4.961503           3.950106e+05               3.891369   \n",
       "std        5.670385           3.082481e+05               1.165359   \n",
       "min        0.000000           5.000000e+04               1.000000   \n",
       "25%        0.000000           2.000000e+05               3.000000   \n",
       "50%        2.000000           3.000000e+05               4.000000   \n",
       "75%       11.000000           5.000000e+05               5.000000   \n",
       "max       18.000000           3.000000e+06               6.000000   \n",
       "\n",
       "       Interest_Rate  Processing_Fee  EMI_Loan_Submitted          Var4  \\\n",
       "count   27726.000000    27420.000000        27726.000000  87020.000000   \n",
       "mean       19.197474     5131.150839        10999.528377      2.949805   \n",
       "std         5.834213     4725.837644         7512.323050      1.697720   \n",
       "min        11.990000      200.000000         1176.410000      0.000000   \n",
       "25%        15.250000     2000.000000         6491.600000      1.000000   \n",
       "50%        18.000000     4000.000000         9392.970000      3.000000   \n",
       "75%        20.000000     6250.000000        12919.040000      5.000000   \n",
       "max        37.000000    50000.000000       144748.280000      7.000000   \n",
       "\n",
       "           LoggedIn     Disbursed  \n",
       "count  87020.000000  87020.000000  \n",
       "mean       0.029350      0.014629  \n",
       "std        0.168785      0.120062  \n",
       "min        0.000000      0.000000  \n",
       "25%        0.000000      0.000000  \n",
       "50%        0.000000      0.000000  \n",
       "75%        0.000000      0.000000  \n",
       "max        1.000000      1.000000  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/listen/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:4: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
      "of pandas will change to not sort by default.\n",
      "\n",
      "To accept the future behavior, pass 'sort=False'.\n",
      "\n",
      "To retain the current behavior and silence the warning, pass 'sort=True'.\n",
      "\n",
      "  after removing the cwd from sys.path.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(124737, 27)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并train和test为一个数据集，便于一起作特征工程\n",
    "train['source'] = 'train'\n",
    "test['source'] = 'test'\n",
    "data = pd.concat([train,test],ignore_index=True)\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 检查异常点/缺省值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "City                      1401\n",
       "DOB                          0\n",
       "Device_Type                  0\n",
       "Disbursed                37717\n",
       "EMI_Loan_Submitted       84901\n",
       "Employer_Name              113\n",
       "Existing_EMI               111\n",
       "Filled_Form                  0\n",
       "Gender                       0\n",
       "ID                           0\n",
       "Interest_Rate            84901\n",
       "Lead_Creation_Date           0\n",
       "Loan_Amount_Applied        111\n",
       "Loan_Amount_Submitted    49535\n",
       "Loan_Tenure_Applied        111\n",
       "Loan_Tenure_Submitted    49535\n",
       "LoggedIn                 37717\n",
       "Mobile_Verified              0\n",
       "Monthly_Income               0\n",
       "Processing_Fee           85346\n",
       "Salary_Account           16801\n",
       "Source                       0\n",
       "Var1                         0\n",
       "Var2                         0\n",
       "Var4                         0\n",
       "Var5                         0\n",
       "source                       0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.apply(lambda x: sum(x.isnull()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 类别型特征情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Gender有2个不同取值，各取值和出现的次数\n",
      "\n",
      "Male      71398\n",
      "Female    53339\n",
      "Name: Gender, dtype: int64\n",
      "\n",
      "City有724个不同取值，各取值和出现的次数\n",
      "\n",
      "Delhi                  17936\n",
      "Bengaluru              15522\n",
      "Mumbai                 15425\n",
      "Hyderabad              10410\n",
      "Chennai                 9895\n",
      "Pune                    7427\n",
      "Kolkata                 4282\n",
      "Ahmedabad               2528\n",
      "Jaipur                  1892\n",
      "Gurgaon                 1743\n",
      "Coimbatore              1659\n",
      "Thane                   1306\n",
      "Chandigarh              1266\n",
      "Surat                   1149\n",
      "Visakhapatnam           1080\n",
      "Indore                  1051\n",
      "Vadodara                 893\n",
      "Nagpur                   879\n",
      "Lucknow                  813\n",
      "Ghaziabad                795\n",
      "Bhopal                   735\n",
      "Kochi                    692\n",
      "Patna                    675\n",
      "Faridabad                651\n",
      "Noida                    549\n",
      "Madurai                  534\n",
      "Gautam Buddha Nagar      485\n",
      "Dehradun                 444\n",
      "Raipur                   430\n",
      "Bhubaneswar              407\n",
      "                       ...  \n",
      "Khagaria                   1\n",
      "SILVASSA                   1\n",
      "Haldia                     1\n",
      "LUNAWADA                   1\n",
      "GANDEVI                    1\n",
      "Sheikhpura                 1\n",
      "Raisen                     1\n",
      "Siruguppa                  1\n",
      "RADHANPUR                  1\n",
      "Chinnamiram                1\n",
      "Hazaribagh                 1\n",
      "Pulwama                    1\n",
      "Kannauj                    1\n",
      "Latehar                    1\n",
      "Kandhamal                  1\n",
      "Sawai Madhopur             1\n",
      "Lakshadweep                1\n",
      "Leh                        1\n",
      "Champawat                  1\n",
      "Bandipore                  1\n",
      "Malkangiri                 1\n",
      "Kupwara                    1\n",
      "Mainpuri                   1\n",
      "Lohit                      1\n",
      "Bageshwar                  1\n",
      "Narayanpur                 1\n",
      "Tawang                     1\n",
      "Magadh                     1\n",
      "Champhai                   1\n",
      "North Cachar Hills         1\n",
      "Name: City, Length: 723, dtype: int64\n",
      "\n",
      "Employer_Name有57194个不同取值，各取值和出现的次数\n",
      "\n",
      "0                                               6900\n",
      "TATA CONSULTANCY SERVICES LTD (TCS)              754\n",
      "COGNIZANT TECHNOLOGY SOLUTIONS INDIA PVT LTD     558\n",
      "ACCENTURE SERVICES PVT LTD                       476\n",
      "GOOGLE                                           408\n",
      "HCL TECHNOLOGIES LTD                             337\n",
      "ICICI BANK LTD                                   337\n",
      "IBM CORPORATION                                  265\n",
      "INDIAN AIR FORCE                                 258\n",
      "INFOSYS TECHNOLOGIES                             257\n",
      "INDIAN ARMY                                      243\n",
      "GENPACT                                          240\n",
      "WIPRO TECHNOLOGIES                               235\n",
      "TYPE SLOWLY FOR AUTO FILL                        219\n",
      "IKYA HUMAN CAPITAL SOLUTIONS LTD                 204\n",
      "ARMY                                             203\n",
      "HDFC BANK LTD                                    201\n",
      "INDIAN RAILWAY                                   201\n",
      "STATE GOVERNMENT                                 199\n",
      "WIPRO BPO                                        186\n",
      "INDIAN NAVY                                      183\n",
      "CONVERGYS INDIA SERVICES PVT LTD                 165\n",
      "OTHERS                                           159\n",
      "IBM GLOBAL SERVICES INDIA LTD                    158\n",
      "TECH MAHINDRA LTD                                158\n",
      "CONCENTRIX DAKSH SERVICES INDIA PVT LTD          154\n",
      "CAPGEMINI INDIA PVT LTD                          152\n",
      "SERCO BPO PVT LTD                                149\n",
      "SUTHERLAND GLOBAL SERVICES PVT LTD               141\n",
      "ADECCO INDIA PVT LTD                             140\n",
      "                                                ... \n",
      "C. VEDHI                                           1\n",
      "JAGDISH SINGH                                      1\n",
      "DQ ENTERTAINMENT                                   1\n",
      "SAI PRAVEEN                                        1\n",
      "B.SIVAKUMAR                                        1\n",
      "BENGAL TOOLS LTD                                   1\n",
      "PRADNYA                                            1\n",
      "HNV CASTINGS PVT LTD                               1\n",
      "SMS CONCAST ENGINEERING INDIA PVT LTD              1\n",
      "AIHIKA HERBOCARE                                   1\n",
      "FINLACE CONSULTING                                 1\n",
      "QQQQ                                               1\n",
      "INDIAHOMES                                         1\n",
      "BHARAT MEDICAL CORPORTION INDORE                   1\n",
      "KOTAK MAHINDRA INVESTMENT LTD                      1\n",
      "INFOTECH HAL LIMITED                               1\n",
      "WB GOVT                                            1\n",
      "TCABS PVT LTD                                      1\n",
      "MSA WOOD WORKS                                     1\n",
      "BHOJWANI BUILDER                                   1\n",
      "N PAVAN KUMAR                                      1\n",
      "L N T TRANSPORTATION INFRASTRU LTD                 1\n",
      "NILKANTH EARTH MOVERS                              1\n",
      "CHERALATHAN ASSOCIATES                             1\n",
      "CHINTAMANI METAL UDYOG LTD                         1\n",
      "VGN JEWELLERY PVT LTD                              1\n",
      "MAXX BUSINESS SYATEMS                              1\n",
      "KAMAL SOLANKY                                      1\n",
      "SUNIL CHAVAN                                       1\n",
      "ASISH RANJAN DHALSAMANT                            1\n",
      "Name: Employer_Name, Length: 57193, dtype: int64\n",
      "\n",
      "Salary_Account有59个不同取值，各取值和出现的次数\n",
      "\n",
      "HDFC Bank                                          25180\n",
      "ICICI Bank                                         19547\n",
      "State Bank of India                                17110\n",
      "Axis Bank                                          12590\n",
      "Citibank                                            3398\n",
      "Kotak Bank                                          2955\n",
      "IDBI Bank                                           2213\n",
      "Punjab National Bank                                1747\n",
      "Bank of India                                       1713\n",
      "Bank of Baroda                                      1675\n",
      "Standard Chartered Bank                             1434\n",
      "Canara Bank                                         1385\n",
      "Union Bank of India                                 1330\n",
      "Yes Bank                                            1120\n",
      "ING Vysya                                            996\n",
      "Corporation bank                                     948\n",
      "Indian Overseas Bank                                 901\n",
      "State Bank of Hyderabad                              854\n",
      "Indian Bank                                          773\n",
      "Oriental Bank of Commerce                            761\n",
      "IndusInd Bank                                        711\n",
      "Andhra Bank                                          706\n",
      "Central Bank of India                                648\n",
      "Syndicate Bank                                       614\n",
      "Bank of Maharasthra                                  576\n",
      "HSBC                                                 474\n",
      "State Bank of Bikaner & Jaipur                       448\n",
      "Karur Vysya Bank                                     435\n",
      "State Bank of Mysore                                 385\n",
      "Federal Bank                                         377\n",
      "Vijaya Bank                                          354\n",
      "Allahabad Bank                                       345\n",
      "UCO Bank                                             344\n",
      "State Bank of Travancore                             333\n",
      "Karnataka Bank                                       279\n",
      "United Bank of India                                 276\n",
      "Dena Bank                                            268\n",
      "Saraswat Bank                                        265\n",
      "State Bank of Patiala                                263\n",
      "South Indian Bank                                    223\n",
      "Deutsche Bank                                        176\n",
      "Abhyuday Co-op Bank Ltd                              161\n",
      "The Ratnakar Bank Ltd                                113\n",
      "Tamil Nadu Mercantile Bank                           103\n",
      "Punjab & Sind bank                                    84\n",
      "J&K Bank                                              78\n",
      "Lakshmi Vilas bank                                    69\n",
      "Dhanalakshmi Bank Ltd                                 66\n",
      "State Bank of Indore                                  32\n",
      "Catholic Syrian Bank                                  27\n",
      "India Bulls                                           21\n",
      "B N P Paribas                                         15\n",
      "Firstrand Bank Limited                                11\n",
      "GIC Housing Finance Ltd                               10\n",
      "Bank of Rajasthan                                      8\n",
      "Kerala Gramin Bank                                     4\n",
      "Industrial And Commercial Bank Of China Limited        3\n",
      "Ahmedabad Mercantile Cooperative Bank                  1\n",
      "Name: Salary_Account, dtype: int64\n",
      "\n",
      "Mobile_Verified有2个不同取值，各取值和出现的次数\n",
      "\n",
      "Y    80928\n",
      "N    43809\n",
      "Name: Mobile_Verified, dtype: int64\n",
      "\n",
      "Var1有19个不同取值，各取值和出现的次数\n",
      "\n",
      "HBXX    84901\n",
      "HBXC    12952\n",
      "HBXB     6502\n",
      "HAXA     4214\n",
      "HBXA     3042\n",
      "HAXB     2879\n",
      "HBXD     2818\n",
      "HAXC     2171\n",
      "HBXH     1387\n",
      "HCXF      990\n",
      "HAYT      710\n",
      "HAVC      570\n",
      "HAXM      386\n",
      "HCXD      348\n",
      "HCYS      318\n",
      "HVYS      252\n",
      "HAZD      161\n",
      "HCXG      114\n",
      "HAXF       22\n",
      "Name: Var1, dtype: int64\n",
      "\n",
      "Filled_Form有2个不同取值，各取值和出现的次数\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "N    96740\n",
      "Y    27997\n",
      "Name: Filled_Form, dtype: int64\n",
      "\n",
      "Device_Type有2个不同取值，各取值和出现的次数\n",
      "\n",
      "Web-browser    92105\n",
      "Mobile         32632\n",
      "Name: Device_Type, dtype: int64\n",
      "\n",
      "Var2有7个不同取值，各取值和出现的次数\n",
      "\n",
      "B    53481\n",
      "G    47338\n",
      "C    20366\n",
      "E     1855\n",
      "D      918\n",
      "F      770\n",
      "A        9\n",
      "Name: Var2, dtype: int64\n",
      "\n",
      "Source有34个不同取值，各取值和出现的次数\n",
      "\n",
      "S122    55249\n",
      "S133    42900\n",
      "S159     7999\n",
      "S143     6140\n",
      "S127     2804\n",
      "S137     2450\n",
      "S134     1900\n",
      "S161     1109\n",
      "S151     1018\n",
      "S157      929\n",
      "S153      705\n",
      "S144      447\n",
      "S156      432\n",
      "S158      294\n",
      "S123      112\n",
      "S141       83\n",
      "S162       60\n",
      "S124       43\n",
      "S150       19\n",
      "S160       11\n",
      "S136        5\n",
      "S155        5\n",
      "S138        5\n",
      "S139        4\n",
      "S129        4\n",
      "S135        2\n",
      "S140        1\n",
      "S154        1\n",
      "S125        1\n",
      "S130        1\n",
      "S131        1\n",
      "S132        1\n",
      "S142        1\n",
      "S126        1\n",
      "Name: Source, dtype: int64\n",
      "\n",
      "Var4有8个不同取值，各取值和出现的次数\n",
      "\n",
      "3    36280\n",
      "1    34316\n",
      "5    29092\n",
      "4     9411\n",
      "2     8481\n",
      "0     3564\n",
      "7     3264\n",
      "6      329\n",
      "Name: Var4, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "cat_features = ['Gender','City','Employer_Name','Salary_Account','Mobile_Verified','Var1','Filled_Form','Device_Type','Var2','Source','Var4']\n",
    "for col in cat_features:\n",
    "    num_vlaules = len(data[col].unique())\n",
    "    print(\"\\n%s有%d个不同取值，各取值和出现的次数\\n\"%(col,num_vlaules))\n",
    "    print(data[col].value_counts())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 合并稀疏取值的样本  city employername salary source\n",
    "LightGBM对类别特征建立直方图时，当特征取值数目超过max_bin(默认255)，会去掉样本数目少的类别： 统计该特征下每一种离散值出现的次数，并从高到低排序，并过滤掉出现次数较少的特征值, 然后为每一个特征值，建立一个bin容器, 对于在bin容器内出现次数较少的特征值直接过滤掉，不建立bin容器。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat_feature = ['City','Employer_Name','Salary_Account','Source']\n",
    "rare_thresholds = [100 , 30 , 40 , 40]\n",
    "j = 0\n",
    "for col in cat_feature:\n",
    "    #各个取值的样本数\n",
    "    value_counts_col = data[col].value_counts(dropna = False)\n",
    "    #样本数小于阈值为稀疏样本\n",
    "    rare_threshold = rare_thresholds[j]\n",
    "    value_counts_rare = list(value_counts_col[value_counts_col < rare_threshold].index)\n",
    "    #稀有值合并为“others”\n",
    "    rare_index = data[col].isin(value_counts_rare)\n",
    "    data.loc[data[col].isin(value_counts_rare),col] = \"Others\"\n",
    "    \n",
    "    j = j + 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# \n",
    "将DOB出生日期转化为更适合题目的申请贷款年龄"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    37\n",
       "1    30\n",
       "2    34\n",
       "3    28\n",
       "4    31\n",
       "Name: Age, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建一个‘Age’\n",
    "data['Age'] = pd.to_datetime(data['Lead_Creation_Date']).dt.year - pd.to_datetime(data['DOB']).dt.year\n",
    "#去掉DOB原始字段\n",
    "data.drop(['DOB', 'Lead_Creation_Date'],axis=1,inplace=True)\n",
    "data['Age'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将不合理的贷款年限设置为缺失值NAN\n",
    "data['Loan_Tenure_Applied'].replace([10, 6, 7, 8, 9],value = np.nan, inplace = True)\n",
    "data['Loan_Tenure_Submitted'].replace(6, np.nan, inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "#去除不需要预测的特征列\n",
    "data.drop('LoggedIn',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>City</th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Employer_Name</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Gender</th>\n",
       "      <th>ID</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>...</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>source</th>\n",
       "      <th>Age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>104</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>20000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>39</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>143</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>13.25</td>\n",
       "      <td>...</td>\n",
       "      <td>35000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>train</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>48</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>104</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>22500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>31</td>\n",
       "      <td>18</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>48</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>104</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>35000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>31</td>\n",
       "      <td>18</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>train</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>56</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>104</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>100000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>train</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   City  Device_Type  Disbursed  EMI_Loan_Submitted  Employer_Name  \\\n",
       "0     7            1        0.0                 NaN            104   \n",
       "1    39            1        0.0              6762.9            143   \n",
       "2    48            1        0.0                 NaN            104   \n",
       "3    48            1        0.0                 NaN            104   \n",
       "4    56            1        0.0                 NaN            104   \n",
       "\n",
       "   Existing_EMI  Filled_Form  Gender           ID  Interest_Rate ...   \\\n",
       "0           0.0            0       0  ID000002C20            NaN ...    \n",
       "1           0.0            0       1  ID000004E40          13.25 ...    \n",
       "2           0.0            0       1  ID000007H20            NaN ...    \n",
       "3           0.0            0       1  ID000008I30            NaN ...    \n",
       "4       25000.0            0       1  ID000009J40            NaN ...    \n",
       "\n",
       "   Monthly_Income  Processing_Fee  Salary_Account  Source  Var1  Var2  Var4  \\\n",
       "0           20000             NaN               7       1     5     6     1   \n",
       "1           35000             NaN               9       1    17     6     3   \n",
       "2           22500             NaN              31      18     5     1     1   \n",
       "3           35000             NaN              31      18     5     1     3   \n",
       "4          100000             NaN               7      15     5     1     3   \n",
       "\n",
       "   Var5  source  Age  \n",
       "0     0   train   37  \n",
       "1    13   train   30  \n",
       "2     0   train   34  \n",
       "3    10   train   28  \n",
       "4    17   train   31  \n",
       "\n",
       "[5 rows x 25 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#类别性特征转化为数值型    lightGBM支持类别型但不支持字符输入\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "le = LabelEncoder()\n",
    "feats_to_encode = ['City', 'Employer_Name', 'Salary_Account','Device_Type','Filled_Form','Gender','Mobile_Verified','Source','Var1','Var2','Var4']\n",
    "for col in feats_to_encode:\n",
    "    data[col] = le.fit_transform(data[col].astype(str))\n",
    "       #df[cat] = le.fit_transform(df[cat].astype(str))\n",
    "\n",
    "data.head()#显示处理后的数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "#区分train 和 test   数据集\n",
    "train = data.loc[data['source']=='train']\n",
    "test = data.loc[data['source']=='test']\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/listen/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py:3697: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  errors=errors)\n"
     ]
    }
   ],
   "source": [
    "train.drop('source',axis=1,inplace=True)\n",
    "test.drop(['source','Disbursed'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "train.to_csv('FE_train.csv',index=False)\n",
    "test.to_csv('FE_test.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
